/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.19
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   其它指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "otherinstructionview.h"
#include "ui_otherinstructionview.h"
#include "../../programView/programview.h"


OtherInstructionView::OtherInstructionView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::OtherInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
    otherInstruction2View = new OtherInstruction2View(styleId);
    otherInstruction2View->otherInstructionView = this;

    for(int i = 0; i < 200; i ++)
    {
        ui->timerIndex_comboBox->addItem(QString::number(i + 1));
        ui->timerIndex_comboBox_2->addItem(QString::number(i + 1));
    }
}

void OtherInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->forward_Btn->setGeometry(10,350,70,40);
        ui->next_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void OtherInstructionView::updateView()
{
    ui->RSR_GBox->setEnabled(false);
    ui->UALM_GBox->setEnabled(false);
    ui->timer_GBox->setEnabled(false);
    ui->OVERRIDE_GBox->setEnabled(false);
    ui->message_GBox->setEnabled(false);

    if(EM_OTHER_INSTRUCTION_RSR == selectInstructionType)
    {
        ui->RSR_GBox->setEnabled(true);
        ui->RSR_radioButton->setChecked(true);
        ui->RSRIndex_comboBox->setCurrentIndex(rsrIndex - 1);
        ui->RSRValue_comboBox->setCurrentIndex(rsrValueType);
    }
    else if(EM_OTHER_INSTRUCTION_UALM == selectInstructionType)
    {
        ui->UALM_GBox->setEnabled(true);
        ui->UALM_radioButton->setChecked(true);
        ui->UALM_lineEdit->setText(ualmInfo);
    }
    else if(EM_OTHER_INSTRUCTION_TIMER == selectInstructionType)
    {
        ui->timer_GBox->setEnabled(true);
        ui->timer_radioButton->setChecked(true);
        ui->timerIndex_comboBox->setCurrentIndex(timerIndex - 1);
        ui->timerDeal_comboBox->setCurrentIndex(timerStatusType);
    }
    else if(EM_OTHER_INSTRUCTION_TIMER_2 == selectInstructionType)
    {
        ui->timer_GBox->setEnabled(true);
        ui->timer_radioButton_2->setChecked(true);
        ui->timerIndex_comboBox_2->setCurrentIndex(timerIndex - 1);
        ui->timer_lineEdit->setText(timerValue);
    }
    else if(EM_OTHER_INSTRUCTION_OVERRIDE == selectInstructionType)
    {
        ui->OVERRIDE_GBox->setEnabled(true);
        ui->rate_radioButton->setChecked(true);
        ui->rate_lineEdit->setText(QString::number(overrideValue));
        ui->rate_slider->setSliderPosition(overrideValue);
    }
    else if(EM_OTHER_INSTRUCTION_MESSAGE == selectInstructionType)
    {
        ui->message_GBox->setEnabled(true);
        ui->message_radioButton->setChecked(true);
        ui->message_lineEdit->setText(message);
    }

    otherInstruction2View->updateView();
}

void OtherInstructionView::getInput()
{
    rsrIndex = ui->RSRIndex_comboBox->currentIndex() + 1;
    rsrValueType = ui->RSRValue_comboBox->currentIndex();

    ualmInfo = ui->UALM_lineEdit->text();

    timerIndex = ui->timerIndex_comboBox->currentIndex() + 1;
    timerStatusType = ui->timerDeal_comboBox->currentIndex();
    timerValue = ui->timer_lineEdit->text();

    overrideValue = ui->rate_lineEdit->text().toInt();

    message = ui->message_lineEdit->text();

    otherInstruction2View->getInput();
}

void OtherInstructionView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void OtherInstructionView::on_next_Btn_clicked()
{
    this->close();
    otherInstruction2View->show();
}

void OtherInstructionView::on_rate_slider_sliderMoved(int position)
{
    overrideValue = position;
    ui->rate_lineEdit->setText(QString::number(overrideValue));
}

void OtherInstructionView::on_rate_slider_valueChanged(int value)
{
    overrideValue = value;
    ui->rate_lineEdit->setText(QString::number(overrideValue));
}

void OtherInstructionView::on_timer_radioButton_clicked()
{
    emit selectTimerInstruction();
}

void OtherInstructionView::on_timer_radioButton_2_clicked()
{
    emit selectTimerInstruction2();
}

void OtherInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/otherViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);

   otherInstruction2View->changeLanguage();
}
